<template>
  <uni-page-wrapper>
    <uni-page-body>
      <uni-view class="loginBg">
        <!-- <uni-view style="fontsize: 12px; float: right; margintop: 10px">
          <span
            @click="switchZh"
            :style="{ color: lang === 'zh' ? '#fe9e1c' : '' }"
            >中文</span
          >
          <span style="margin: 0 5px">|</span>
          <span
            @click="switchEn"
            :style="{ color: lang === 'en' ? '#fe9e1c' : '' }"
            >English</span
          >
        </uni-view> -->

        <uni-view class="title">{{ $t("login.Choose Amazon,choose Wealth") }}</uni-view>
        <uni-view class="formItem">
          <uni-image class="icon">
            <div
              style="
                background-image: url('');
                background-position: 0% 0%;
                background-size: 100% 100%;
                background-repeat: no-repeat;
              "
            >
            </div>
            <img
              src=""
            />
          </uni-image>
          <uni-view class="line"> </uni-view>
          <uni-input class="input">
            <div class="uni-input-wrapper">
              <input
                class="uni-input uni-input-input"
                ref="input1"
                :placeholder='$t("login.Please enter username or tel")'
                maxlength="140"
                enterkeyhint="done"
                autocomplete="off"
                :value="username"
                @input="onKeyInput('username', $event)"
              />
            </div>
          </uni-input>
        </uni-view>
        <uni-view class="formItem">
          <uni-image class="icon">
            <div
              style="
                background-image: url('');
                background-position: 0% 0%;
                background-size: 100% 100%;
                background-repeat: no-repeat;
              "
            >
            </div>
            <img
              src=""
            />
          </uni-image>
          <uni-view class="line"> </uni-view>

          <uni-input class="input">
            <div class="uni-input-wrapper">
              <input
                class="uni-input uni-input-input"
                ref="input1"
                :placeholder='$t("login.Please enter login password")'
                maxlength="140" 
                enterkeyhint="done"
                autocomplete="off"
                type="password"
                :value="password"
                @input="onKeyInput('password', $event)"
              />
            </div>
          </uni-input>
        </uni-view>
        <uni-view class="submitBtn" @click="signIn">{{ $t("login.Sign in") }}</uni-view>
        <uni-view class="other">
          <uni-view class="item" @click="toRegister"
            >{{ $t("login.No account? Open an account now") }}</uni-view
          >
        </uni-view>
      </uni-view>
    </uni-page-body>
  </uni-page-wrapper>
</template>

<script>
import service from '@/store/service.js'
export default {
  data() {
    return {
      username: "",
      password: "",
      lang: uni.getStorageSync("lang"),
    };
  },
  methods: {
    switchZh() {
      //中文
      this._i18n.locale = "zh";
      uni.setStorageSync("lang", "zh");
      this.lang = uni.getStorageSync("lang");
    },
    switchEn() {
      //英文
      this._i18n.locale = "en";
      uni.setStorageSync("lang", "en");
      this.lang = uni.getStorageSync("lang");
    },
    onKeyInput(type, event) {
      this[type] = event.target.value;
    },
    toRegister() {
      uni.redirectTo({
        url: "/pages/register/register",
      });
    },
    signIn() {
        uni.showLoading();
		service.normal(this,service.api.app_login,{
			username:this.username,
			password:this.password
		},function(self,res){
            uni.hideLoading();
			uni.setStorageSync('token',res.token)
			//调用登录接口，成功后跳转到首页
			uni.reLaunch({
			  url: "/pages/home/home",
			});
		})
    },
  },
};
</script>

<style>
@import url(./login.css);
</style>